package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.annotation.TingshuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserCollectVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @Operation(summary = "模拟登录弹窗提示")
    @GetMapping("/findUserSubscribePage/{pn}/{pz}")
    public Result findUserSubscribePage(@PathVariable(value = "pn") Long pn,
                                        @PathVariable(value = "pz") Long pz) {
        return Result.ok();
    }

    @GetMapping("/collect/{trackId}")
    @TingshuLogin
    @Operation(summary = "收藏与取消收藏声音")
    public Result collect(@PathVariable(value = "trackId") Long trackId) {
        Boolean flag = userInfoService.collect(trackId);
        return Result.ok(flag);
    }

    @GetMapping("/isCollect/{trackId}")
    @Operation(summary = "是否收藏声音")
    @TingshuLogin
    public Result isCollect(@PathVariable(value = "trackId") Long trackId) {

        Boolean flag = userInfoService.isCollect(trackId);
        return Result.ok(flag);

    }

    @GetMapping("/findUserCollectPage/{pn}/{pz}")
    @Operation(summary = "查询用户收藏过的声音列表分页展示")
    @TingshuLogin
    public Result findUserCollectPage(@PathVariable(value = "pn") Long pn,
                                      @PathVariable(value = "pz") Long pz) {


        IPage<UserCollectVo> pageParam = new Page<UserCollectVo>(pn, pz);


        pageParam = userInfoService.findUserCollectPage(pageParam);
        return Result.ok(pageParam);
    }

}

